﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CreateContentMail.aspx.cs" Inherits="famails.BackEnd.page.CreateContentMail" MasterPageFile="~/Master.Master" %>

<%@Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor"%>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
   <%-- <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>--%>
    <style type="text/css">
        .heartbeat {
            display: none;
            margin: 5px;
            color: blue;
        }
    </style>
   <%-- <script language="javascript" type="text/javascript">
        $(function () {
            setInterval(KeepSessionAlive, 10000);
        });

        function KeepSessionAlive() {
            $.post("/backend/page/KeepSessionAlive.ashx", null, function () {
                //$("#result").append("<p>Session is alive and kicking!<p/>");
                setInterval(function () { beatHeart(5); }, 10000);
            });
        }
        function beatHeart(times) {
            var interval = setInterval(function () {
                $(".heartbeat").fadeIn(500, function () {
                    $(".heartbeat").fadeOut(500);
                });
            }, 1000); // beat every second

            // after n times, let's clear the interval (adding 100ms of safe gap)
            setTimeout(function () { clearInterval(interval); }, (2000 * times) + 500);
        }
   </script>--%>
      <script type="text/javascript">
          function insertHello() {
              var firtHello = document.getElementById("ContentPlaceHolder1_txtWelcome");
              var lastHello = document.getElementById("ContentPlaceHolder1_txtAfterWelcome");
              var customerName = document.getElementById("ContentPlaceHolder1_rdoCustomerName");
              var Wellcome = firtHello.value + " " + "[khachhang]" + " " + lastHello.value;
              if (customerName.checked == true) {
                  Wellcome;
              }

              var currentData = CKEDITOR.instances.ContentPlaceHolder1_txtBody.getData();
              var displayData = Wellcome + "</br>" + currentData;
              CKEDITOR.instances.ContentPlaceHolder1_txtBody.setData(displayData);
          }

          function signatureChange() {
              var SignId = $('select#<%=drlSign.ClientID%> option:selected').val();
              $.ajax({
                  type: "POST",
                  url: "send-register.aspx/getSign",
                  data: '{SignId: "' + SignId + '" }',
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: signatureChangeSuccess,
                  failure: function (response) {
                      alert("Chữ ký không tồn tại!");
                  }
              });
          }
          function signatureChangeSuccess(response) {
              var dataResponse = response.d;
              var currentData = CKEDITOR.instances.ContentPlaceHolder1_txtBody.getData();
              var displayData = currentData + "</br>" + dataResponse;
              CKEDITOR.instances.ContentPlaceHolder1_txtBody.setData(displayData);
          }function checkSpam() {

              var _title = document.getElementById("ContentPlaceHolder1_txtSubject").value;
              var _content = CKEDITOR.instances.ContentPlaceHolder1_txtBody.getData();
              var encodedHTML = escape(_content);
              $.ajax({
                  type: "POST",
                  url: "send-register.aspx/Spam",
                  data: "{title:'" + _title + "',content:'" + encodedHTML + "'}",
                  contentType: "application/json; charset=utf-8",
                  dataType: "json",
                  success: spamCheckSuccess,
                  failure: function (response) {
                      alert("Chữ ký không tồn tại!");
                  }
              });
          }

          function spamCheckSuccess(response) {
              var dataResponse = response.d;
              if (dataResponse != null) {
                  var check = document.getElementById("ContentPlaceHolder1_lblDataRespone");
                  check.innerHTML = dataResponse;
                  //$("#dialog-form").dialog("open");
                  $('#window').jqxWindow('open');
              }
          }
          $(function () {              

              var basicDemo = (function () {
                  //Adding event listeners
                  function _addEventListeners() {

                      $('#btnCheck').click(function () {
                          //loadtree();
                          var x = ($(window).width() - $("#window").jqxWindow('width')) / 2 + $(window).scrollLeft();
                          var y = ($(window).height() - $("#window").jqxWindow('height')) / 2 + $(window).scrollTop();
                          $("#window").jqxWindow({ position: { x: x, y: y } });
                          $('#window').jqxWindow('open');
                      });
                      $('#hideWindowButton').click(function () {
                          $('#window').jqxWindow('close');
                      });
                  };
                  //Creating all page elements which are jqxWidgets
                  function _createElements() {

                      //$('#resizeCheckBox').jqxCheckBox({ width: '185px', checked: true });
                      //$('#dragCheckBox').jqxCheckBox({ width: '185px', checked: true });
                  };
                  //Creating the demo window
                  function _createWindow() {
                      $('#window').jqxWindow({
                          showCollapseButton: true, maxHeight: 500, maxWidth: 800, minHeight: 200, minWidth: 200, height: 300, width: 800,
                          initContent: function () {
                              //$('#tab').jqxTabs({ height: '100%', width: '100%' });
                              $('#window').jqxWindow('focus');
                              $('#window').jqxWindow('close');
                          }
                      });
                  }; 
                  return {
                      config: {
                          dragArea: null
                      },
                      init: function () {
                          //Creating all jqxWindgets except the window
                          _createElements();
                          //Attaching event listeners
                          _addEventListeners();
                          //Adding jqxWindow
                          _createWindow();
                      }
                  };
              }());
              //Initializing the demo
              basicDemo.init();
          });
        </script>
    <div id="window">
        <div id="windowHeader">
            <span>Thống kê nội dung các quy tắc vi phạm của mẫu email dạng HTML chi tiết như bên dưới:
            </span>
        </div>
        <div style="overflow: hidden;" id="windowContent">

            <fieldset>
                <asp:Label ID="lblDataRespone" runat="server" Text="Data"></asp:Label>
            </fieldset>
        </div>
    </div>
    <div style="width:100%;padding:10px;">
        <!--start content 01-->
        <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="padding:0px;border:1px solid #333;margin-bottom:10px;">
            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="padding:10px 20px;background:#000;color:#fff;font-size:18px;font-weight:bold;position:relative;">   
                Soạn thư
            </div>
			    
			    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="padding:0px;">
                <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto;padding:10px;">
		          <asp:Panel Visible="false" ID="pnError" runat="server">
                    <div class="error-box round">
                        <asp:Label ID="lblError"  runat="server" Text=""></asp:Label> 
                    </div>
                  </asp:Panel>
                  <asp:Panel Visible="false" ID="pnSuccess" runat="server">
                    <div class="confirmation-box round">
                        <asp:Label ID="lblSuccess"  runat="server" Text=""></asp:Label> 
                    </div>
                  </asp:Panel>
                </div>
			      <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="padding:0px;">
                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto;padding:10px;">
                        <fieldset>
                            <p>
                                <label for="simple-input" style="font-weight: bolder; text-transform: none">
                                    Loại nội dung</label>
                                    <asp:DropDownList ID="ddlContentType" runat="server" CssClass="form-control" style="border:1px solid #333;border-radius:0px;">
                                        <asp:ListItem Text="Autoresponder" Value="1" Selected="True"></asp:ListItem>
                                        <asp:ListItem Text="Broadcast" Value="2"></asp:ListItem>
                                    </asp:DropDownList>
                            </p>
                        </fieldset>
                    </div>
                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto;padding:10px;">
                        <fieldset>
                            <p>
                                <label for="simple-input" style="font-weight: bolder; text-transform: none">
                                    Tiêu đề</label>
                                    <asp:HiddenField ID="hdfContentId" runat="server" />
                                    <asp:TextBox ID="txtSubject" CssClass="form-control" style="border:1px solid #333;border-radius:0px;" runat="server" 
                                         ToolTip="Nhập tiêu đề bức thư của bạn"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                                                                                ControlToValidate="txtSubject" Display="Dynamic" ErrorMessage="Vui lòng nhập vào tiêu đề !" 
                                                                                ValidationGroup="Check_Input_Insert"></asp:RequiredFieldValidator>
                            </p>
                        </fieldset>
                    </div>
                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto;padding:10px;">
                        <fieldset>
                            <p>
                                <small>
                                <div style="font-size:14px;background:none;border:1px solid #999;padding:10px;line-height:18px;">
                                    Để đưa tên khách hàng vào nội dung bạn vui lòng nhập <b>[khachhang]</b> hệ thống sẽ tự động thay vào<br />
                                    VD:Khách hàng là: <b>Nguyễn Văn A</b> khi bạn điền:  Chào, <b>[khachhang]</b> chúc mừng bạn...=> Chào, <b>Nguyễn Văn A</b> chúc mừng bạn...<br />
                                    Lưu ý: nếu khách hàng chưa cung cấp thông tin họ tên, hệ thống sẽ thay đổi bằng địa chỉ email.
                                </div></small>
                            </p>
                        </fieldset>
                    </div>
                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="padding:5px 5px 5px 10px;">
                        <div class="col-md-2 col-lg-2 col-sm-2 col-xs-12" style="padding-left:0px;padding-right:5px;">
                            <asp:TextBox ID="txtWelcome" CssClass="form-control" style="color:#333;border:1px solid #333;border-radius:0px;float:left;" runat="server"
                                ToolTip="Nhập lời chào cho bức thư!">Chào</asp:TextBox>

                        </div>
                        <div class="col-md-2 col-lg-2 col-sm-3 col-xs-12" style="padding-left:0px;padding-top:5px;padding-bottom:5px;height:34px">
                            <asp:RadioButton ID="rdoCustomerName" Checked="true" GroupName="groupWelcome" runat="server" />Tên
                            khách hàng

                        </div>
                        <div class="col-md-2 col-lg-2 col-sm-3 col-xs-12" style="padding-left:0px;padding-top:5px;padding-bottom:5px;height:34px">
                            <asp:RadioButton ID="rdoCustomerEmail" GroupName="groupWelcome" runat="server" />Email
                            khách hàng
                        </div>
                        <div class="col-md-4 col-lg-4 col-sm-3 col-xs-10" style="padding-left:0px;padding-right:5px;">
                            <asp:TextBox ID="txtAfterWelcome" style="color:#333;border:1px solid #333;border-radius:0px;" CssClass="form-control"
                                runat="server">thân mến !</asp:TextBox>

                        </div>
                            <div class="col-md-2 col-lg-2 col-sm-1 col-xs-2" style="padding:0px;padding-right:5px;text-align:right;">
                                <asp:Button style="background:#333;color:#fff;text-align:center;padding:6px 15px;border-radius:0px;width:100%;min-width:32px;min-height:32px" onclick="insertHello()" class="btn">
                                    <span class="fa fa-plus" style="float:left;font-size:20px"></span>
                                    <span class="visible-md visible-lg">Thêm lời chào</span>
                                </asp:Button>
                            </div> 
                    </div>
                <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto;padding:10px;">
                    <fieldset>
                    <label for="simple-input" style="font-weight: bolder; text-transform: none">
                        Nội dung thư </label>
                    <CKEditor:CKEditorControl ID="txtBody" runat="server" CausesValidation="True" ResizeEnabled="False"></CKEditor:CKEditorControl>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                                        ControlToValidate="txtBody" Display="Dynamic" ErrorMessage="Vui lòng nhập vào nội dung !" 
                                                        ValidationGroup="Check_Input_Insert"></asp:RequiredFieldValidator>
                     
                    </fieldset>
                </div>
                <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto;padding:10px;">
                    <fieldset>
                        <p>
                                <label for="simple-input" style="font-weight: bolder; text-transform: none">
                                    Thêm chữ ký </label>
                                    <asp:DropDownList ID="drlSign" CssClass="form-control" style="border-radius:0px;border:1px solid #333;" runat="server"
                                        AutoPostBack="false" onchange="signatureChange()">
                                    </asp:DropDownList>
                        </p>
                    </fieldset>
                </div>
                <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto;padding:10px;">
<%--                    <p>					
                            <asp:Button ID="btnSaveContent" ValidationGroup="Check_Input_Insert" Text="Lưu" style="background:#333;color:#fff;text-align:center;padding:6px 15px;border-radius:0px;" runat="server" CssClass="btn" OnClick="btnSaveContent_Click"/>
                            <asp:Button ID="btnRefesh" style="background:#333;color:#fff;text-align:center;padding:6px 15px;border-radius:0px;" runat="server" Text="Làm mới" CssClass="btn" OnClick="btnRefesh_Click"/>
                            <asp:Button ID="btnPreview" ToolTip="Xem với các trình duyệt Email: Gmail, Yahoo, Hotmail.." style="background:#333;color:#fff;text-align:center;padding:6px 15px;border-radius:0px;" runat="server" Text="Kiểm tra HTML" CssClass="btn" OnClick="btnPreview_Click"/>
                            <asp:Button ID="btnCancel" PostBackUrl="~/backend/page/list-content-mail.aspx" style="background:#333;color:#fff;text-align:center;padding:6px 15px;border-radius:0px;" runat="server" Text="Hủy" CssClass="btn" OnClick="btnCancel_Click"/>
                    </p>--%>
                            <button runat="server" class="btn col-md-2 col-xs-6 col-sm-4 col-lg-1" style="border:1px solid #fff;background:#333;color:#fff;text-align:center;padding:6px 15px;border-radius:0px;" onserverclick="btnSaveContent_Click">
                                <i class="fa fa-save"></i> Lưu
                            </button>
                            <button runat="server" class="btn col-md-2 col-xs-6 col-sm-4 col-lg-2" style="border:1px solid #fff;background:#333;color:#fff;text-align:center;padding:6px 15px;border-radius:0px;" onserverclick="btnRefesh_Click">
                                <i class="fa fa-refresh"></i> Làm mới
                            </button>
                <button id="btnCheck" style="border: 1px solid #fff; background: #333; color: #fff; text-align: center; padding: 6px 15px; border-radius: 0px;" type="button" value="Đánh giá nội dung" class="btn col-md-2 col-xs-6 col-sm-4 col-lg-2" onclick="checkSpam()">
                    <i style="margin-right:10px;" class="fa fa-check"></i>Đánh giá
                </button>
                            <button runat="server" class="btn col-md-2 col-xs-6 col-sm-4 col-lg-2" style="border:1px solid #fff;background:#333;color:#fff;text-align:center;padding:6px 15px;border-radius:0px;" onserverclick="btnPreview_Click">
                                <i class="fa fa-eye"></i> Xem trước
                            </button>
                            <button runat="server" class="btn col-md-2 col-xs-6 col-sm-4 col-lg-1" style="border:1px solid #fff;background:#333;color:#fff;text-align:center;padding:6px 15px;border-radius:0px;" onserverclick="btnCancel_Click">
                                <i class="fa fa-sign-out"></i> Ðóng
                            </button>

                </div>
			</div>
	    </div>
    </div>    		     	      
 </div>	  

</asp:Content>

